package com.tensai.teach.beijing.xml;

import org.junit.Test;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.util.Arrays;
import java.util.List;

public class XmlTest {

	@Test
	public void test2() throws JAXBException {
		Product p1 = new Product();
		p1.setId("11021");
		p1.setName("Apple");

		Product p2 = new Product();
		p2.setId("11022");
		p2.setName("Banana");

		List<Product> list = Arrays.asList(p1,p2);

		Order2 order = new Order2();
		order.setId("1102");
		order.setPrice(45.67);
		order.setProduct(list);

		JAXBContext context = JAXBContext.newInstance(Order2.class);
		Marshaller marshaller = context.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

		marshaller.marshal(order, System.out);
	}
}
